import Vue from 'vue';

//指令注册  全局  局部
Vue.directive('timeupdate',{
    bind(el,binding,vnode){
        console.log(el,binding,vnode);

        let {value} = binding;
        el.currentTime = value/1000;
        

        el.updateFun = function(e){
            vnode.context.type = 'update';
            // console.log(e.target.currentTime);
            // console.log(vnode,'vnode');
            vnode.context.curTime = e.target.currentTime; //秒单位
        }

        el.addEventListener('timeupdate',el.updateFun)
    },
    update(el,binding,vnode){
        if(vnode.context.type === 'click'){
            let {value} = binding;
            el.currentTime = value/1000;
        }
    },
    unbind(el){
        el.removeEventListener('timeupdate',el.updateFun)
    }
})